```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring事务失效原因深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
        }
        .serif {
            font-family: 'Noto Serif SC', serif;
        }
        .hero-bg {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
        }
        .card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
        }
        .code-block {
            background-color: #1e293b;
            color: #f8fafc;
            border-radius: 0.5rem;
            padding: 1.25rem;
            position: relative;
        }
        .code-block::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 2px;
            background: linear-gradient(90deg, #4f46e5, #7c3aed);
        }
        .highlight {
            position: relative;
        }
        .highlight::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 30%;
            background-color: rgba(79, 70, 229, 0.2);
            z-index: -1;
        }
        .section-divider {
            height: 2px;
            background: linear-gradient(90deg, transparent, #94a3b8, transparent);
            margin: 3rem 0;
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <section class="hero-bg text-white py-20 px-4">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col items-center text-center">
                <span class="inline-block px-3 py-1 mb-4 text-xs font-semibold tracking-wider text-indigo-100 uppercase bg-indigo-700 rounded-full">技术深度解析</span>
                <h1 class="text-4xl md:text-5xl font-bold mb-6 serif">Spring事务失效的六大原因</h1>
                <p class="text-xl md:text-2xl text-indigo-100 max-w-3xl leading-relaxed">
                    深入剖析事务失效的原因与解决方案，确保你的应用数据一致性
                </p>
                <div class="mt-8 flex space-x-4">
                    <div class="flex items-center">
                        <i class="fas fa-clock mr-2 text-indigo-200"></i>
                        <span class="text-indigo-200">阅读时间: 8分钟</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-calendar-alt mr-2 text-indigo-200"></i>
                        <span class="text-indigo-200">2023年更新</span>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-12">
        <!-- Intro -->
        <section class="mb-16">
            <p class="text-lg text-slate-600 leading-relaxed mb-6">
                Spring事务管理是Java企业应用开发中的核心功能之一，但在实际使用中，我们经常会遇到事务失效的问题。本文深入分析了Spring事务失效的六大原因，并提供详细的解决方案，帮助开发者避免常见陷阱。
            </p>
            <div class="bg-white rounded-xl p-6 shadow-md border border-slate-100">
                <h3 class="text-xl font-bold text-slate-800 mb-4 flex items-center">
                    <i class="fas fa-lightbulb text-yellow-500 mr-3"></i>
                    <span class="highlight">关键知识</span>
                </h3>
                <p class="text-slate-600">
                    Spring 事务失效的原因通常与配置、注解使用、事务边界、异常处理、数据源问题以及 AOP 代理有关。通过检查这些方面，可以解决大多数事务失效的问题，确保事务管理的正确性。
                </p>
            </div>
        </section>

        <!-- Visualization -->
        <section class="mb-16">
            <h2 class="text-2xl font-bold text-slate-800 mb-6 serif">事务失效原因关系图</h2>
            <div class="bg-white rounded-xl p-6 shadow-md border border-slate-100">
                <div class="mermaid">
                    graph TD
                    A[Spring事务失效] --> B[配置问题]
                    A --> C[注解使用不当]
                    A --> D[事务边界问题]
                    A --> E[异常处理不当]
                    A --> F[数据源问题]
                    A --> G[AOP代理问题]
                    
                    B --> B1[未启用事务管理]
                    B --> B2[事务管理器未配置]
                    
                    C --> C1[注解未应用或错误]
                    C --> C2[传播行为不当]
                    C --> C3[隔离级别不适合]
                    
                    D --> D1[跨方法事务]
                    D --> D2[非Spring管理代码]
                    
                    E --> E1[未捕获异常]
                    E --> E2[Checked异常处理]
                    
                    F --> F1[连接问题]
                    F --> F2[数据库不支持]
                    
                    G --> G1[代理未生效]
                </div>
            </div>
        </section>

        <div class="section-divider"></div>

        <!-- Reason 1 -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="bg-indigo-100 text-indigo-800 w-10 h-10 rounded-full flex items-center justify-center mr-4">
                    <span class="font-bold">1</span>
                </div>
                <h2 class="text-2xl font-bold text-slate-800 serif">事务管理配置问题</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-6">
                <div class="card bg-white rounded-xl p-6 shadow-md border border-slate-100">
                    <h3 class="text-xl font-semibold text-slate-800 mb-3 flex items-center">
                        <i class="fas fa-cog text-indigo-500 mr-2"></i>
                        <span class="highlight">未启用事务管理</span>
                    </h3>
                    <p class="text-slate-600 mb-4">
                        确保在 Spring 配置中启用了事务管理。这通常通过添加 <code class="bg-slate-100 px-1 py-0.5 rounded">@EnableTransactionManagement</code> 注解或者在 XML 配置中设置事务管理器来实现。
                    </p>
                    <div class="code-block">
                        <pre><code class="text-sm">@Configuration
@EnableTransactionManagement
public class AppConfig {
    // Configuration code
}</code></pre>
                    </div>
                </div>
                
                <div class="card bg-white rounded-xl p-6 shadow-md border border-slate-100">
                    <h3 class="text-xl font-semibold text-slate-800 mb-3 flex items-center">
                        <i class="fas fa-database text-indigo-500 mr-2"></i>
                        <span class="highlight">事务管理器未配置</span>
                    </h3>
                    <p class="text-slate-600 mb-4">
                        需要确保在 Spring 配置中定义了事务管理器 Bean。例如，使用 <code class="bg-slate-100 px-1 py-0.5 rounded">@Bean</code> 注解或 XML 配置定义一个 <code class="bg-slate-100 px-1 py-0.5 rounded">DataSourceTransactionManager</code> 或 <code class="bg-slate-100 px-1 py-0.5 rounded">JpaTransactionManager</code>。
                    </p>
                    <div class="code-block">
                        <pre><code class="text-sm">@Bean
public PlatformTransactionManager transactionManager(DataSource dataSource) {
    return new DataSourceTransactionManager(dataSource);
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <div class="section-divider"></div>

        <!-- Reason 2 -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="bg-indigo-100 text-indigo-800 w-10 h-10 rounded-full flex items-center justify-center mr-4">
                    <span class="font-bold">2</span>
                </div>
                <h2 class="text-2xl font-bold text-slate-800 serif">事务注解使用不当</h2>
            </div>
            
            <div class="grid md:grid-cols-3 gap-6">
                <div class="card bg-white rounded-xl p-6 shadow-md border border-slate-100">
                    <h3 class="text-xl font-semibold text-slate-800 mb-3 flex items-center">
                        <i class="fas fa-tag text-indigo-500 mr-2"></i>
                        <span class="highlight">注解未正确应用</span>
                    </h3>
                    <p class="text-slate-600 mb-4">
                        确保在需要事务管理的方法上正确使用 <code class="bg-slate-100 px-1 py-0.5 rounded">@Transactional</code> 注解。注意，<code class="bg-slate-100 px-1 py-0.5 rounded">@Transactional</code> 只能作用于 public 方法。
                    </p>
                    <div class="code-block">
                        <pre><code class="text-sm">@Service
public class MyService {
    @Transactional
    public void performTransaction() {
        // Method code
    }
}</code></pre>
                    </div>
                </div>
                
                <div class="card bg-white rounded-xl p-6 shadow-md border border-slate-100">
                    <h3 class="text-xl font-semibold text-slate-800 mb-3 flex items-center">
                        <i class="fas fa-random text-indigo-500 mr-2"></i>
                        <span class="highlight">传播行为不当</span>
                    </h3>
                    <p class="text-slate-600 mb-4">
                        事务传播行为（如 <code class="bg-slate-100 px-1 py-0.5 rounded">REQUIRED</code>, <code class="bg-slate-100 px-1 py-0.5 rounded">REQUIRES_NEW</code>, <code class="bg-slate-100 px-1 py-0.5 rounded">NESTED</code>）配置不正确可能导致事务失效。
                    </p>
                    <div class="code-block">
                        <pre><code class="text-sm">@Transactional(propagation = Propagation.REQUIRES_NEW)
public void performNestedTransaction() {
    // Method code
}</code></pre>
                    </div>
                </div>
                
                <div class="card bg-white rounded-xl p-6 shadow-md border border-slate-100">
                    <h3 class="text-xl font-semibold text-slate-800 mb-3 flex items-center">
                        <i class="fas fa-shield-alt text-indigo-500 mr-2"></i>
                        <span class="highlight">隔离级别不适合</span>
                    </h3>
                    <p class="text-slate-600 mb-4">
                        事务隔离级别设置不当可能导致事务的并发问题或脏读。需要选择合适的隔离级别，例如 <code class="bg-slate-100 px-1 py-0.5 rounded">READ_COMMITTED</code> 或 <code class="bg-slate-100 px-1 py-0.5 rounded">REPEATABLE_READ</code>。
                    </p>
                    <div class="code-block">
                        <pre><code class="text-sm">@Transactional(isolation = Isolation.READ_COMMITTED)
public void performTransaction() {
    // Method code
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <div class="section-divider"></div>

        <!-- Reason 3 -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="bg-indigo-100 text-indigo-800 w-10 h-10 rounded-full flex items-center justify-center mr-4">
                    <span class="font-bold">3</span>
                </div>
                <h2 class="text-2xl font-bold text-slate-800 serif">事务边界问题</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-6">
                <div class="card bg-white rounded-xl p-6 shadow-md border border-slate-100">
                    <h3 class="text-xl font-semibold text-slate-800 mb-3 flex items-center">
                        <i class="fas fa-exchange-alt text-indigo-500 mr-2"></i>
                        <span class="highlight">跨方法事务</span>
                    </h3>
                    <p class="text-slate-600">
                        如果一个事务方法调用了另一个带有事务注解的方法，事务可能不会正常传播。需要确保事务边界在方法调用链中得到正确管理。
                    </p>
                </div>
                
                <div class="card bg-white rounded-xl p-6 shadow-md border border-slate-100">
                    <h3 class="text-xl font-semibold text-slate-800 mb-3 flex items-center">
                        <i class="fas fa-code text-indigo-500 mr-2"></i>
                        <span class="highlight">非Spring管理代码</span>
                    </h3>
                    <p class="text-slate-600">
                        如果在 Spring 管理的事务外部调用了 Spring 管理的事务方法，事务将不生效。例如，在原生的 JDBC 代码中进行事务操作不会被 Spring 事务管理器控制。
                    </p>
                </div>
            </div>
        </section>

        <div class="section-divider"></div>

        <!-- Reason 4 -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="bg-indigo-100 text-indigo-800 w-10 h-10 rounded-full flex items-center justify-center mr-4">
                    <span class="font-bold">4</span>
                </div>
                <h2 class="text-2xl font-bold text-slate-800 serif">异常处理不当</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-6">
                <div class="card bg-white rounded-xl p-6 shadow-md border border-slate-100">
                    <h3 class="text-xl font-semibold text-slate-800 mb-3 flex items-center">
                        <i class="fas fa-exclamation-triangle text-indigo-500 mr-2"></i>
                        <span class="highlight">未捕获的异常</span>
                    </h3>
                    <p class="text-slate-600 mb-4">
                        Spring 默认只有在遇到 <code class="bg-slate-100 px-1 py-0.5 rounded">RuntimeException</code> 或其子类时才会进行回滚。
                    </p>
                </div>
                
                <div class="card bg-white rounded-xl p-6 shadow-md border border-slate-100">
                    <h3 class="text-xl font-semibold text-slate-800 mb-3 flex items-center">
                        <i class="fas fa-check-circle text-indigo-500 mr-2"></i>
                        <span class="highlight">Checked异常处理</span>
                    </h3>
                    <p class="text-slate-600 mb-4">
                        对于 <code class="bg-slate-100 px-1 py-0.5 rounded">checked</code> 异常，默认情况下不会回滚。需要在 <code class="bg-slate-100 px-1 py-0.5 rounded">@Transactional</code> 注解中显式指定。
                    </p>
                    <div class="code-block">
                        <pre><code class="text-sm">@Transactional(rollbackFor = Exception.class)
public void performTransaction() throws Exception {
    // Method code
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <div class="section-divider"></div>

        <!-- Reason 5 & 6 -->
        <section class="mb-16">
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <div class="flex items-center mb-6">
                        <div class="bg-indigo-100 text-indigo-800 w-10 h-10 rounded-full flex items-center justify-center mr-4">
                            <span class="font-bold">5</span>
                        </div>
                        <h2 class="text-2xl font-bold text-slate-800 serif">数据源问题</h2>
                    </div>
                    
                    <div class="card bg-white rounded-xl p-6 shadow-md border border-slate-100">
                        <h3 class="text-xl font-semibold text-slate-800 mb-3 flex items-center">
                            <i class="fas fa-plug text-indigo-500 mr-2"></i>
                            <span class="highlight">数据库连接问题</span>
                        </h3>
                        <p class="text-slate-600 mb-4">
                            数据库连接问题（如连接池配置不当）可能导致事务无法正常提交或回滚。需要确保数据库连接池配置正确，连接稳定。
                        </p>
                        
                        <h3 class="text-xl font-semibold text-slate-800 mb-3 flex items-center mt-6">
                            <i class="fas fa-server text-indigo-500 mr-2"></i>
                            <span class="highlight">数据库不支持事务</span>
                        </h3>
                        <p class="text-slate-600">
                            某些数据库或数据源可能不支持事务操作。在这种情况下，Spring 事务将无法生效。
                        </p>
                    </div>
                </div>
                
                <div>
                    <div class="flex items-center mb-6">
                        <div class="bg-indigo-100 text-indigo-800 w-10 h-10 rounded-full flex items-center justify-center mr-4">
                            <span class="font-bold">6</span>
                        </div>
                        <h2 class="text-2xl font-bold text-slate-800 serif">Spring AOP 代理问题</h2>
                    </div>
                    
                    <div class="card bg-white rounded-xl p-6 shadow-md border border-slate-100">
                        <h3 class="text-xl font-semibold text-slate-800 mb-3 flex items-center">
                            <i class="fas fa-project-diagram text-indigo-500 mr-2"></i>
                            <span class="highlight">事务代理未生效</span>
                        </h3>
                        <p class="text-slate-600">
                            <code class="bg-slate-100 px-1 py-0.5 rounded">@Transactional</code> 注解依赖于 Spring 的 AOP 代理机制。如果 AOP 代理未正确配置，事务将不会生效。确保服务类被 Spring 管理，并且 AOP 配置正确。
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Summary -->
        <section class="bg-indigo-50 rounded-xl p-8 mb-16">
            <h2 class="text-2xl font-bold text-slate-800 mb-6 serif">总结与最佳实践</h2>
            <div class="grid md:grid-cols-2 gap-6">
                <div>
                    <h3 class="text-lg font-semibold text-indigo-800 mb-3">检查清单</h3>
                    <ul class="space-y-2 text-slate-600">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                            <span>确保已启用事务管理并配置了事务管理器</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                            <span>正确应用@Transactional注解（仅public方法）</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                            <span>根据业务需求设置合适的传播行为和隔离级别</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                            <span>正确处理异常（特别是checked异常）</span>
                        </li>
                    </ul>
                </div>
                <div>
                    <h3 class="text-lg font-semibold text-indigo-800 mb-3">调试技巧</h3>
                    <ul class="space-y-2 text-slate-600">
                        <li class="flex items-start">
                            <i class="fas fa-search text-indigo-500 mt-1 mr-2"></i>
                            <span>开启Spring事务调试日志（logging.level.org.springframework.transaction=DEBUG）</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-code text-indigo-500 mt-1 mr-2"></i>
                            <span>检查AOP代理是否生效（打印类名看是否有$Proxy）</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-database text-indigo-500 mt-1 mr-2"></i>
                            <span>验证数据库事务支持（SELECT * FROM information_schema.engines）</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8">
        <div class="container mx-auto px-4 max-w-5xl">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                    <p class="text-gray-400">专注分享高质量技术文章</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-indigo-400 hover:text-indigo-300 transition-colors duration-200 flex items-center">
                        <i class="fas fa-external-link-alt mr-2"></i>
                        <span>访问技术小馆</span>
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-6 pt-6 text-center text-sm text-gray-500">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            themeVariables: {
                primaryColor: '#4f46e5',
                primaryTextColor: '#fff',
                primaryBorderColor: '#4f46e5',
                lineColor: '#7c3aed'
            }
        });
    </script>
</body>
</html>
```